import homework6.rengou.person
import homework6.rengou.dog
import random


class Fight:
    A = homework6.rengou.person.Person(1)
    B = homework6.rengou.person.Person(2)
    C = homework6.rengou.dog.Dog(1)
    D = homework6.rengou.dog.Dog(2)
    E = homework6.rengou.dog.Dog(3)
    i = random.randint(0, 1)
    ListP = [A, B]
    ListD = [C, D, E]
    if i == 1:
        Flag = True

    def fighting(self):
        while len(self.ListD) > 0 and len(self.ListP) > 0:
            i = random.randint(0, len(self.ListP) - 1)
            j = random.randint(0, len(self.ListD) - 1)
            while True:
                if self.ListP[i].life <= 0 or self.ListD[j].life <= 0:
                    i = random.randint(0, len(self.ListP) - 1)
                    j = random.randint(0, len(self.ListD) - 1)
                else:
                    break
            if self.Flag:
                self.ListP[i].attack(self.ListD[j])
                self.ListD[j].be_attack(self.ListP[i])
                print("%s号人攻击了%s号狗" % (self.ListP[i].name, self.ListD[j].name))
                if self.ListD[j].life <= 0:
                    del self.ListD[j]
                self.Flag = False
            else:
                self.ListD[j].attack(self.ListP[i])
                self.ListP[i].be_attack(self.ListD[j])
                print("%s号狗攻击了%s号人" % (self.ListD[j].name, self.ListP[i].name))
                if self.ListP[i].life <= 0:
                    del self.ListP[i]
                self.Flag = True


if __name__ == '__main__':
    m = Fight()
    m.fighting()


